package com.xmall.sys.controller;

import com.xmall.define.base.Result;
import com.xmall.define.request.sys.TimerTaskQueryRequest;
import com.xmall.sys.service.other.ITimerTaskService;
import com.xmall.timer.dto.TimerTaskDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 定时任务
 */
@RequestMapping("/service/sys/timerTask")
@RestController
public class TimerTaskController {

    @Resource
    private ITimerTaskService timerTaskService;

    /**
     * 执行任务
     */
    @PreAuthorize("hasAuthority('sys:timerTask:list')")
    @PostMapping("/executeOnce")
    public Result executeOnce(@Validated @RequestBody TimerTaskQueryRequest request) {
        timerTaskService.executeOnce(request);
        return Result.success();
    }

    /**
     * 任务列表
     */
    @PreAuthorize("hasAuthority('sys:timerTask:list')")
    @GetMapping("/taskList")
    public Result<List<TimerTaskDto>> taskList() {
        return Result.success(timerTaskService.taskList());
    }

}
